/**
 * Created by wxl on 2016/12/16.
 */
import {
    HOME_DATA_SUCCESS,
    HOME_DATA_FAILURE,
    HOME_SWIPER_DATA_SUCCESS,
    HOME_CUBE_DATA_SUCCESS,
    HOME_NEW_DATA_SUCCESS
} from '../actions/types'
import { createReducer } from 'redux-immutablejs'
import {fromJS} from 'immutable'

const initialState = fromJS({
   homeData:[], isFetching:true,
   swiperData:[],cubeData:[],newData:[]
})

export const home= createReducer(initialState,{
    [HOME_DATA_FAILURE]: (state,action)=>{
        state.set('isFetching',true)
    },
    [HOME_DATA_SUCCESS]: (state,action)=>{
        return state.merge({
            homeData:action.req.data.info,
            isFetching:false
        })
    },
    [HOME_SWIPER_DATA_SUCCESS]:(state,action)=>{
       return state.merge({"swiperData":action.req.data.info})
    },
    [HOME_CUBE_DATA_SUCCESS]:(state,action)=>{
        return state.merge({"cubeData":action.req.data.info})
    },
    [HOME_NEW_DATA_SUCCESS]:(state,action)=>{
        return state.merge({"newData":action.req.data.info})
    },
})

